package com.ruoyi.teaching.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.teaching.bo.YaStudentTaskslBo;
import com.ruoyi.teaching.domain.YaStageTaskSubmit;
import com.ruoyi.teaching.domain.YaStudent;
import com.ruoyi.teaching.vo.YaStudentTasksVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teaching.domain.YaStageTasks;
import com.ruoyi.teaching.service.IYaStageTasksService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 任务Controller
 * 
 * @author ZBX
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/stage_tasks")
public class YaStageTasksController extends BaseController
{
    @Autowired
    private IYaStageTasksService yaStageTasksService;

    //list/student
    @RequiresPermissions("teaching:stage_tasks:list")
    @PostMapping("/list/student")
    public List<YaStudentTaskslBo> listStudent(@RequestBody YaStudentTasksVo yaStudentTasksVo)
    {
        return yaStageTasksService.selectYaStudentTasksSubmitList(yaStudentTasksVo);
    }

    @RequiresPermissions("teaching:stage_tasks:list")
    @PutMapping("/checkStudentSubmit")
    public AjaxResult checkStudentSubmit(@RequestBody YaStageTaskSubmit yaStageTaskSubmit)
    {
        yaStageTasksService.checkStudentSubmit(yaStageTaskSubmit);
        return AjaxResult.success();
    }

    /**
     * 查询任务列表
     */
    @RequiresPermissions("teaching:stage_tasks:list")
    @GetMapping("/list")
    public TableDataInfo list(YaStageTasks yaStageTasks)
    {
        startPage();
        List<YaStageTasks> list = yaStageTasksService.selectYaStageTasksList(yaStageTasks);
        return getDataTable(list);
    }

    /**
     * 导出任务列表
     */
    @RequiresPermissions("teaching:stage_tasks:export")
    @Log(title = "任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YaStageTasks yaStageTasks)
    {
        List<YaStageTasks> list = yaStageTasksService.selectYaStageTasksList(yaStageTasks);
        ExcelUtil<YaStageTasks> util = new ExcelUtil<YaStageTasks>(YaStageTasks.class);
        util.exportExcel(response, list, "任务数据");
    }

    /**
     * 获取任务详细信息
     */
    @RequiresPermissions("teaching:stage_tasks:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yaStageTasksService.selectYaStageTasksById(id));
    }

    /**
     * 新增任务
     */
    @RequiresPermissions("teaching:stage_tasks:add")
    @Log(title = "任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YaStageTasks yaStageTasks)
    {
        return toAjax(yaStageTasksService.insertYaStageTasks(yaStageTasks));
    }

    /**
     * 修改任务
     */
    @RequiresPermissions("teaching:stage_tasks:edit")
    @Log(title = "任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YaStageTasks yaStageTasks)
    {
        return toAjax(yaStageTasksService.updateYaStageTasks(yaStageTasks));
    }

    /**
     * 删除任务
     */
    @RequiresPermissions("teaching:stage_tasks:remove")
    @Log(title = "任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yaStageTasksService.deleteYaStageTasksByIds(ids));
    }
}
